# -*- mode: python; coding: utf-8; -*-
##--------------------------------------------------------------------------##
##
## Copyright (C) 1998-2003 Markus Oberhumer <markus@oberhumer.com>
## Copyright (C) 2003 Mt. Hood Playing Card Co.
## Copyright (C) 2005-2010 Skomoroh <skomoroh@users.sourceforge.net>
## Copyright (C) 2010-2013 Jeremy Austin-Bardo <tjaustinbardo@gmail.com>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program.  If not, see <http://www.gnu.org/licenses/>.
##
##--------------------------------------------------------------------------##
__docformat__ = 'restructuredtext en'
__all__ = []

from ... import pilelib as stack
from ...forms import ganjifa as glayout
from ...gamelib import info as gi, game
from ...packlib import info as cs
from ...utillib.misc import kwdefault
from .. import katzenschwanz

GT, SL = gi.GT, gi.SL
Wrap = stack.StackWrapper


class Shamsher(cs.Mughal_Deck, game.Game):
    """
    Finish 1 deck on _foundation_ within a turn.

    :CVariables:
      _layout_ : pysollib.layout.Layout
        .. pysollib.layouts.ganifa.GhulamLayout

        - row [14 over 2 row N, vert offset]
        - talon [1 S, no offset]
        - reserve [2 vert E, 2 vert W S foundation, no offset]
        - foundation [4 vert E, 4 vert W, no offset]

      _talon_ : pysollib.stack.Stack
        .. pysollib.stack.InitialDealTalon

        No redeals.

      _foundation_ : pysollib.stack.Stack
        .. stack.SS_Foundation

        Build up in rank by same suit. Play top. Base ace.

      _row_ : pysollib.stack.Stack
        .. pysollib.stacks.RK_RowStack (max_cards=12)

        Init 6 open card per with remain 1st. Build down in rank alone. Play
        sequence. Max 12 card.

      _reserves_ : pysollib.stack.Stack
        .. pysollib.stack.ReserveStack

        Build any. Play top. Max 1 card.

      _hint_ : pysollib.hint.AbstractHint
        .. pysollib.hint.DefaultHint
    """
    __info__ = dict(id=14403, name='Shamsher',
                    category=cs.TYPE_MUGHAL_GANJIFA, game_type=GT.FREECELL,
                    decks=1, skill_level=SL.MOSTLY_SKILL, version='0.50fc')
    __author__ = 'Mt. Hood Playing Card'
    __version__ = 7.70

    _layout_ = glayout.GhulamLayout
    _talon_ = stack.InitialDealTalon
    _foundation_ = stack.SS_Foundation
    _row_ = Wrap(stack.RK_RowStack, max_cards=12)

    def _create_game(self, **kw):
        kwdefault(kw, rows=14, ncols=7, reserves=4, texts=False,
                          playcards=12)
        return super(Shamsher, self)._create_game(**kw)

    def _start(self, rows=7):
        for i in range(6):
            self.s['talon'].dealRow(frames=0)
        self._play_sound('deal')
        self.s['talon'].dealRowAvail()


class Ashrafi(Shamsher):
    """
    Finish 1 deck on _foundation_ within a turn.

    :CVariables:
      _layout_ : pysollib.layout.Layout
        .. pysollib.layouts.ganifa.GhulamLayout

        - row [14 over 2 row N, vert offset]
        - talon [1 S, no offset]
        - reserve [2 vert E, 2 vert W S foundation, no offset]
        - foundation [4 vert E, 4 vert W, no offset]

      _talon_ : pysollib.stack.Stack
        .. pysollib.stack.InitialDealTalon

        No redeals.

      _foundation_ : pysollib.stack.Stack
        .. stack.SS_Foundation

        Build up in rank by same suit. Play top. Base ace.

      _row_ : pysollib.stack.Stack
        .. pysollib.stacks.RK_RowStack (max_cards=12, base_rank=RAJA)

        Init 6 open card per with remain 1st. Build down in rank alone. Play
        sequence. Base raja. Max 12 card.

      _reserves_ : pysollib.stack.Stack
        .. pysollib.stack.ReserveStack

        Build any. Play top. Max 1 card.

      _hint_ : pysollib.hint.AbstractHint
        .. pysollib.hint.DefaultHint
    """
    __info__ = dict(id=14405, name='Ashrafi', category=cs.TYPE_MUGHAL_GANJIFA,
                    game_type=GT.FREECELL, decks=1,
                    skill_level=SL.MOSTLY_SKILL, version='0.50fc')
    __author__ = 'Mt. Hood Playing Card'
    __version__ = 7.70

    _row_ = Wrap(stack.RK_RowStack, max_cards=12, base_rank=cs.RAJA)


class Ghulam(Shamsher):
    """
    Finish 1 deck on _foundation_ within a turn.

    :CVariables:
      _layout_ : pysollib.layout.Layout
        .. pysollib.layouts.ganifa.GhulamLayout

        - row [14 over 2 row N, vert offset]
        - talon [1 S, no offset]
        - reserve [2 vert E, 2 vert W S foundation, no offset]
        - foundation [4 vert E, 4 vert W, no offset]

      _talon_ : pysollib.stack.Stack
        .. pysollib.stack.InitialDealTalon

        No redeals.

      _foundation_ : pysollib.stack.Stack
        .. stack.SS_Foundation

        Build up in rank by same suit. Play top. Base ace.

      _row_ : pysollib.stack.Stack
        .. pysollib.stacks.SS_RowStack (max_cards=12)

        Init 6 open card per with remain 1st. Build down in rank by same suit.
        Play sequence. Max 12 card.

      _reserves_ : pysollib.stack.Stack
        .. pysollib.stack.ReserveStack

        Build any. Play top. Max 1 card.

      _hint_ : pysollib.hint.AbstractHint
        .. pysollib.hint.DefaultHint
    """
    __info__ = dict(id=14402, name='Ghulam', category=cs.TYPE_MUGHAL_GANJIFA,
                    game_type=GT.FREECELL, decks=1,
                    skill_level=SL.MOSTLY_SKILL, version='0.50fc')
    __author__ = 'Mt. Hood Playing Card'
    __version__ = 7.70

    _row_ = Wrap(stack.SS_RowStack, max_cards=12)


class Vajra(cs.Mughal_Deck, katzenschwanz.DerKatzenschwanz):
    """
    Finish 1 deck on _foundation_ within a turn.

    :CVariables:
      _layout_ : pysollib.layout.Layout
        .. pysollib.layouts.CatsTailLayout

        - row [9 horz S reserve, vert offset]
        - talon [1 SW, no offset]
        - reserve [8 N, no offset]
        - foundation [8 over 2 col E, no offset]

      _talon_ : pysollib.stack.Stack
        .. pysollib.stack.InitialDealTalon

        No redeals.

      _foundation_ : pysollib.stack.Stack
        .. stack.SS_Foundation

        Build up in rank by same suit. Play top. Base ace.

      _row_ : pysollib.stack.Stack
        .. pysollib.stack.RK_RowStack (base_rank=GAP)

        Init all cards with raja start pile. Build down in rank alone.
        Play sequence. Base none.

      _reserves_ : pysollib.stack.Stack
        .. pysollib.stack.ReserveStack

        Build any. Play top. Max 1 card.

      _hint_ : pysollib.hint.AbstractHint
        .. pysollib.games.katzenshwanz.DerKatzenschwanzHint
    """
    __info__ = dict(id=16000, name='Vajra', category=cs.TYPE_MUGHAL_GANJIFA,
                    game_type=GT.FREECELL, decks=1,
                    skill_level=SL.MOSTLY_SKILL, version='0.50fc')
    __author__ = 'Mt. Hood Playing Card'
    __version__ = 7.70

    _row_ = Wrap(stack.RK_RowStack, base_rank=cs.GAP)

    def _create_game(self, **kw):
        kwdefault(kw, rows=9, reserves=8)
        return super(Vajra, self)._create_game(**kw)

    def _start(self):
        self._play_sound('deal')
        i = 0
        while self.s['talon'].cards:
            if self.s['talon'].TOPCARD['rank'] == cs.RAJA:
                if self.s['rows'][i].cards:
                    i += 1
            self.s['talon'].dealRow(rows=[self.s['rows'][i]], frames=4)


class Danda(Vajra):
    """
    Finish 1 deck on _foundation_ within a turn.

    :CVariables:
      _layout_ : pysollib.layout.Layout
        .. pysollib.layouts.CatsTailLayout

        - row [9 horz S reserve, vert offset]
        - talon [1 SW, no offset]
        - reserve [8 N, no offset]
        - foundation [8 over 2 col E, no offset]

      _talon_ : pysollib.stack.Stack
        .. pysollib.stack.InitialDealTalon

        No redeals.

      _foundation_ : pysollib.stack.Stack
        .. stack.SS_Foundation

        Build up in rank by same suit. Play top. Base ace.

      _row_ : pysollib.stack.Stack
        .. pysollib.stack.AF_RowStack (base_rank=GAP)

        Init all cards with raja start pile. Build down in rank by alt
        force. Play sequence. Base none.

      _reserves_ : pysollib.stack.Stack
        .. pysollib.stack.ReserveStack

        Build any. Play top. Max 1 card.

      _hint_ : pysollib.hint.AbstractHint
        .. pysollib.games.katzenshwanz.DerKatzenschwanzHint
    """
    __info__ = dict(id=16001, name='Danda', category=cs.TYPE_MUGHAL_GANJIFA,
                    game_type=GT.FREECELL, decks=1,
                    skill_level=SL.MOSTLY_SKILL, version='0.50fc')
    __author__ = 'Mt. Hood Playing Card'
    __version__ = 7.70

    _row_ = Wrap(stack.AF_RowStack, base_rank=cs.GAP)


class Khadga(Vajra):
    """
    Finish 1 deck on _foundation_ within a turn.

    :CVariables:
      _layout_ : pysollib.layout.Layout
        .. pysollib.layouts.CatsTailLayout

        - row [9 horz S reserve, vert offset]
        - talon [1 SW, no offset]
        - reserve [8 N, no offset]
        - foundation [8 over 2 col E, no offset]

      _talon_ : pysollib.stack.Stack
        .. pysollib.stack.InitialDealTalon

        No redeals.

      _foundation_ : pysollib.stack.Stack
        .. stack.SS_Foundation

        Build up in rank by same suit. Play top. Base ace.

      _row_ : pysollib.stack.Stack
        .. pysollib.stack.AC_RowStack (base_rank=GAP)

        Init all cards with raja start pile. Build down in rank by alt
        color. Play sequence. Base none.

      _reserves_ : pysollib.stack.Stack
        .. pysollib.stack.ReserveStack

        Build any. Play top. Max 1 card.

      _hint_ : pysollib.hint.AbstractHint
        .. pysollib.games.katzenshwanz.DerKatzenschwanzHint
    """
    __info__ = dict(id=16002, name='Khadga', category=cs.TYPE_MUGHAL_GANJIFA,
                    game_type=GT.FREECELL, decks=1,
                    skill_level=SL.MOSTLY_SKILL, version='0.50fc')
    __author__ = 'Mt. Hood Playing Card'
    __version__ = 7.70

    _row_ = Wrap(stack.AC_RowStack, base_rank=cs.GAP)


class Makara(Vajra):
    """
    Finish 1 deck on _foundation_ within a turn.

    :CVariables:
      _layout_ : pysollib.layout.Layout
        .. pysollib.layouts.CatsTailLayout

        - row [9 horz S reserve, vert offset]
        - talon [1 SW, no offset]
        - reserve [8 N, no offset]
        - foundation [8 over 2 col E, no offset]

      _talon_ : pysollib.stack.Stack
        .. pysollib.stack.InitialDealTalon

        No redeals.

      _foundation_ : pysollib.stack.Stack
        .. stack.SS_Foundation

        Build up in rank by same suit. Play top. Base ace.

      _row_ : pysollib.stack.Stack
        .. pysollib.stack.SS_RowStack (base_rank=GAP)

        Init all cards with raja start pile. Build down in rank by same
        suit. Play sequence. Base none.

      _reserves_ : pysollib.stack.Stack
        .. pysollib.stack.ReserveStack

        Build any. Play top. Max 1 card.

      _hint_ : pysollib.hint.AbstractHint
        .. pysollib.games.katzenshwanz.DerKatzenschwanzHint
    """
    __info__ = dict(id=16003, name='Makara', category=cs.TYPE_MUGHAL_GANJIFA,
                    game_type=GT.FREECELL, decks=1,
                    skill_level=SL.MOSTLY_SKILL, version='0.50fc')
    __author__ = 'Mt. Hood Playing Card'
    __version__ = 7.70

    _row_ = Wrap(stack.SS_RowStack, base_rank=cs.GAP)


PROVIDES = [Ashrafi, Danda, Ghulam, Khadga, Makara, Shamsher, Vajra]